package listbyorder.access101_200.test168;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/14 12:49
 */
public class Solution1 {

    // Excel表列名称
    public String convertToTitle(int n) {
        char[] chars = new char[]{' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        StringBuilder ans = new StringBuilder();
        return helper(n, chars);
    }

    private String helper(int n, char[] chars) {
        if (n == 0) return "";
        if (n <= 26) return chars[n] + "";

        int decimal = (n - 1) / 26;
        int mod = n % 26;
        return helper(decimal, chars) + helper(mod, chars);
    }
}
